﻿using NHibernate.Validator.Constraints;
using TestBat.IModels.Domain;

namespace TestBat.Models.Domain
{
    public abstract class TestTask : DomainEntity, ITestTask
    {
        [NotNull]
        public virtual ITest Test
        {
            get { return test; }
            set
            {
                if (Equals(test, value))
                    return; // no change needed

                if (test != null)
                    test.TestTasks.Remove(this); // remove from old group

                test = value;

                if (test != null)
                    test.TestTasks.Add(this); // add to new parent's children
            }
        }

        [Range(Min = 0, Max = 255)]
        public virtual uint MaximumPoints { get; set; }

        [NotNull]
        public virtual ISolution Solution
        {
            get { return solution; }
            set
            {
                if (Equals(solution, value))
                    return;

                if (solution != null) // old solution
                    solution.Task = null;

                solution = value;

                if (solution != null) // new solution
                    solution.Task = this;
            }
        }

        [Range(Min = 1)]
        public virtual int Sort
        {
            get;
            set;
        }

        private ITest test;
        private ISolution solution;
    }
}
